# -*- coding: utf-8 -*-
from src.game.entity.living import EntityLiving
from src.handler.sprite import SpriteHandler
from src.game.talent.archer import ArcherTalent
from src.game.talent.mage import MageTalent
import pygame, math

class EntityPlayer(EntityLiving):

    speed = 200.
    name = "entityplayer"

    def __init__(self):
        EntityLiving.__init__(self, 100., MageTalent(self))
        self.width = 0.5
        self.height = 0.5
        self.collision = True
        self.friction = 0.1
        self.mass = 1.0
        self.obstacles = 10
        
    def pickUpItem(self, item):
        pass
    
    def readFromPSO(self, pso):
        EntityLiving.readFromPSO(self, pso)
        self.obstacles = pso.get("obstacles")
        
    def writeToPSO(self, pso):
        EntityLiving.writeToPSO(self, pso)
        pso.set("obstacles", self.obstacles)
    
    def render(self, client, viewport):
        EntityLiving.render(self, client, viewport)
        localX, localY = viewport.globalToLocale(self.x, self.y)
        sprite = SpriteHandler.get("player")
        sprite.set_alpha(255)
        mx, my = pygame.mouse.get_pos()


        rad = math.atan2(client.width / 2 - mx, client.height / 2 - my);
        self.view = rad / (2 * math.pi) * 360

        # rotate around center
        loc = sprite.get_rect().center
        sprite = pygame.transform.rotate(sprite, self.view)
        sprite.get_rect().center = loc

        client.window.surface.blit(sprite, (localX * 64, localY * 64))
